package homework.Abstract;

abstract class Animal {
    protected String name;
    protected int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public abstract void makeSound();

    public void displayInfo() {
        System.out.println("动物信息:");
        System.out.println("名称:" + name);
        System.out.println("年龄:" + age);
    }
}
class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }
    @Override
    public void makeSound() {
        System.out.println("狗发出了汪汪的声音");
    }
}
class Cat extends Animal {
    public Cat(String name, int age) {
        super(name, age);
    }
    @Override
    public void makeSound() {
        System.out.println("猫发出了喵喵的声音");
    }
}

